package cn.kgc.controller;

import cn.kgc.dto.Dto;
import cn.kgc.dto.DtoUtil;
import cn.kgc.service.HomeService;
import cn.kgc.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class HomeController {

    @Autowired
    HomeService homeService;
    /**
     * 查询首页轮播图
     * @return
     */
    @PostMapping("/p/index/queryBanner")
    public Dto<List<HotItemVo>> queryBanner() throws Exception {
        //获取数据
        List<HotItemVo> hotItemVoDto = homeService.queryBanner();
        //返回数据
        return DtoUtil.returnDataSuccess(hotItemVoDto);
    }

    /**
     * 获取所有的商品分类
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/p/index/queryAllType")
    public Dto<List<HomeItemTypeVo>> queryAllType() throws Exception {
        //获取数据
        List<HomeItemTypeVo> homeItemTypeVos = homeService.queryAllType();
        //返回数据
        return DtoUtil.returnDataSuccess(homeItemTypeVos);
    }

    /**
     * 获取首页横向导航数据
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/p/index/queryTransverse")
    public Dto<List<ItemTransverseTypeVo>> queryTransverse() throws Exception {
        //获取数据
        List<List<ItemTransverseTypeVo>> itemTransverseTypeVos = homeService.queryTransverse();
        //返回数据
        return DtoUtil.returnDataSuccess(itemTransverseTypeVos);
    }

    /**
     * 首页今日推荐
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/p/index/queryTodayRecommend")
    public Dto<List<HotItemVo>> queryTodayRecommend() throws Exception {
        List<HotItemsVo> hotItemsVos = homeService.queryTodayRecommend();

        return DtoUtil.returnDataSuccess(hotItemsVos);
    }

    /**
     * 即将开售
     *
     * @return
     * @throws Exception
     */
    @PostMapping("/p/index/queryToSaleItem")
    public Dto queryToSaleItem() throws Exception {
        List<HotItemsVo> hotItemsVos = homeService.queryToSaleItem();

        return DtoUtil.returnDataSuccess(hotItemsVos);
    }

    /**
     * 首页返回不同楼层展示数据
     *
     * @return
     */
    @PostMapping("p/index/queryFloorItems")
    public Dto queryFloorItems() throws Exception {
        List<ItemFloorLevelVo> itemFloorLevelVos = homeService.queryFloorItems();

        return DtoUtil.returnDataSuccess(itemFloorLevelVos);
    }

    /**
     * 不同分类排行
     */
    @PostMapping("/p/index/queryHotItems")
    public Dto queryHotItems(@RequestParam Integer itemTypeId) throws Exception {
        List<HomeItemRangVo> homeItemRangVos = homeService.queryHotItems(itemTypeId);

        return DtoUtil.returnDataSuccess(homeItemRangVos);
    }

    /**
     * 根据token返回用户信息
     * @param token
     * @return
     * @throws Exception
     */
    @PostMapping("/p/index/user/loadCurrentUserByToken")
    public Dto loadCurrentUserByToken(@RequestParam ItemCurrentUserByTokenVo token) throws Exception {
        List<ItemCurrentUserByTokenVo> itemCurrentUserByTokenVos = homeService.loadCurrentUserByToken();

        return DtoUtil.returnDataSuccess(itemCurrentUserByTokenVos);
    }
}
